#ifndef SLAVEPANELFORM_H
#define SLAVEPANELFORM_H

#include <QWidget>
#include <QThread>
#include "common/DataType.h"
#include "link/ModBusTcpWorker.h"

namespace Ui {
class SlavePanelForm;
}

class SlavePanelForm : public QWidget
{
    Q_OBJECT

public:
    explicit SlavePanelForm(QWidget *parent = nullptr);
    ~SlavePanelForm();

    void setProNameDevType(QString proName,int devType);
    void setIPPort(QString address,short port);
    void setReadStartAddressAndRegisterCount(QList<int> startAddress, QList<int> registerCount,int RegisterType);
    void startLoopReadRegister(bool start);

public slots:
    void slot_Devfaults(bool  faultBool);

signals:
    /***type  0:主机  1:从机1   2:从机2  3:从机3 ...  ***/
    void sig_SetProNameDevType(QString proName,int devType);

    void sig_SetIPPort(QString address,short port);
    void sig_SetReadStartAddressAndRegisterCount(QList<int> startAddress, QList<int> registerCount,int RegisterType);
    void sig_StartLoopReadRegister(bool start);

    //写寄存器的数据
    void sig_WriteRegister(WriteData *data);


protected slots:

    //TCP的连接状态
    void slot_ConnectionState(bool State);

    //最终界面显示的浮点数
    void slot_ReadfloatData(int MsgId,QList<float> data);

    //最终界面显示的bool
    void slot_ReadBoolData(int MsgId,QList<bool> data);

private slots:
    void on_btnReset_clicked();      //复位按钮槽函数
    void timeoutWatchDog();          //定时的函数

private:
    Ui::SlavePanelForm *ui;

    QThread* m_Thread;
    ModBusTcpWorker* m_ModBusTcpWorker;//通信

    int m_DevType;
    bool  faultsState;      //设备故障
    bool  faultsStatePre;   //记录上次的设备故障的信息

    QTimer* m_Timer;
};

#endif // SLAVEPANELFORM_H
